package simorg.domain;

import org.dom4j.Element;

import simorg.util.PasswordHash;
import simorg.util.StringUtil;

public class User {

	private int id;
	private String username;
	private String password;
	private String email;
	private String firstName;
	private String lastName;
	private Role role;
	
	public User() {
		this.role = Role.Student;
		this.id = -1;
	}
	
	
	public User(String username, Role role) {
		this.username = username;
		this.role = role;
		this.id = -1;
	}
	
	
	public int getId() {
		return id;
	}



	public void setId(int id) {
		this.id = id;
	}



	public String getUsername() {
		return username;
	}



	public void setUsername(String username) {
		this.username = username;
	}



	public String getPassword() {
		return password;
	}


	public void setPassword(String password) {
		this.password = password;
	}


	public String getEmail() {
		return email;
	}



	public void setEmail(String email) {
		this.email = email;
	}



	public String getFirstName() {
		return firstName;
	}



	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}



	public String getLastName() {
		return lastName;
	}



	public void setLastName(String lastName) {
		this.lastName = lastName;
	}



	public Role getRole() {
		return role;
	}



	public void setRole(Role role) {
		this.role = role;
	}

	public void buildDomainXml(Element root) {
		Element user = root.addElement("user");
		user.addAttribute("id", String.valueOf(this.getId()));
		Element username = user.addElement("username");
		username.setText(StringUtil.nullSafe(this.getUsername()));
		Element password = user.addElement("password");
		password.setText(StringUtil.nullSafe(PasswordHash.nochange));
		Element email = user.addElement("email");
		email.setText(StringUtil.nullSafe(this.getEmail()));
		Element firstName = user.addElement("firstName");
		firstName.setText(StringUtil.nullSafe(this.getFirstName()));
		Element lastName = user.addElement("lastName");
		lastName.setText(StringUtil.nullSafe(this.getLastName()));
		Element role = user.addElement("role");
		role.setText(this.getRole().toString());
		return;
	}
}
